﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using System.Drawing;
using Silvermoon.OpenGL;
using Silvermoon.Shapes;
using Silvermoon.Animations;
using Silvermoon.UI;
using Silvermoon.Controls.Base;
using Silvermoon.Utils;
using Silvermoon.Windows;

namespace Testing
{
    public class TextBoxDemo2 : DemoWindowBase
    {
        private TextBox textBox;

        public TextBoxDemo2()
            : base()
        {
            Title = "MULTILINE TEXTBOX";
            const int scrollbarWidth = VScrollBar.ScrollbarWidth + 2;

            SetTransition(350, TransitionMask.Fade | TransitionMask.Zoom, TransitionMask.Fade | TransitionMask.Zoom);

            // Decorator to surround the scrollpanel with a textbox background:
            Decorator d = new Decorator { Margin = new Margin(0, 64, scrollbarWidth, 8), Background = new TextBoxShape { Color = Color.White } };

            // ScrollPanel which hosts the TextBox and allows the content to be scrolled if it does not fit into the view.
            ScrollPanel panel = new ScrollPanel
            {
                Margin = new Margin(2, 72, 0, 16),
                ScrollbarColor = Color.White,
                IsFocusable = false,
            };

            // Textbox with multiple lines (AcceptReturn = true) and automatic height determination which is reflected by the ScrollPanel host.
            TextBox tb = new TextBox
            {
                AcceptReturn = true,
                Color = Color.White,
                Margin = new Margin(0, 2, scrollbarWidth, null),
                AutoHeight = true,
                // don't use a background for the textbox since the decorator is already presenting a background.
                Background = Shape.Empty,
                Chrome = Shape.Empty
            };


            StringBuilder sb = new StringBuilder();
            for (int i = 1; i < 100; i++)
            {
                sb.Append(i);
                sb.Append('\n');
            }
            tb.Text = sb.ToString();
            panel.Controls.Add(tb);

            textBox = tb;
            Controls.Add(d);
            Controls.Add(panel);
            Color = Color.Black;

            ContentButton btn = new ToolbarButton();
            btn.Content = ImagePool.Plus;
            btn.Visible = true;
            btn.Tap += (s, e) =>
            {
                textBox.Text = "Textbox";
            };

            Button b2 = new Button { Color = PhoneColors.FromArgb(255, 24, 24, 24), Content = "Select", Size = new Size(120, 64) };
            toolbar.Buttons.Add(b2);
            toolbar.Buttons.Add(btn);

            Toolbar myToolbar = Toolbar as Toolbar;
            myToolbar.IsMenuButtonVisible = true;
            myToolbar.MenuItems.Add(new MenuItem { Text = "Lorem Ipsum" });
            myToolbar.MenuItems.Add(new MenuItem { Text = "Exit", Command = Page.BackCommand });

            myToolbar.MenuItems[0].Tap += (s, e) => tb.Text = TextboxDemo.lorem;

        }
    }
}
